﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// kh 的摘要说明
/// </summary>
public class kh:SQLHelper
{
    //定义kh类的数据成员（属性）
    private string knum;
    private string kname;
    private string kaddress;
    private string kwork;
    private string kstate;
    private string kpw;
    private string kphone;
    private string kidcard;
    private string kbirth;
    private string kprovince;
    private string kcity;
    private string kqq;
    private string kmail;
    private string kproblem;
    private string kanswer;

    public string num
    {
        get { return knum; }
        set { knum = value; }
    }
    public string name
    {
        get { return kname; }
        set { kname = value; }
    }
    public string address
    {
        get { return kaddress; }
        set { kaddress = value; }
    }
    public string work
    {
        get { return kwork; }
        set { kwork = value; }
    }
    public string state
    {
        get { return kstate; }
        set { kstate = value; }
    }
    public string pw
    {
        get { return kpw; }
        set { kpw = value; }
    }
    public string phone
    {
        get { return kphone; }
        set { kphone = value; }
    }
    public string idcard
    {
        get { return kidcard; }
        set { kidcard = value; }
    }
    public string birth
    {
        get { return kbirth; }
        set { kbirth = value; }
    }
    public string province
    {
        get { return kprovince; }
        set { kprovince = value; }
    }
    public string city
    {
        get { return kcity; }
        set { kcity = value; }
    }
    public string qq
    {
        get { return kqq; }
        set { kqq = value; }
    }
    public string mail
    {
        get { return kmail; }
        set { kmail = value; }
    }
    public string problem
    {
        get { return kproblem; }
        set { kproblem = value; }
    }
    public string answer
    {
        get { return kanswer; }
        set { kanswer = value; }
    }
	public kh()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    //查找账号num是否存在
    public int IsidExist(kh tmp)
    {
        string sql = "select count(*)from kh where Knum='" + tmp.num + "'";
        int result = tmp.ExeScalar(sql);
        return result;
    }
    //添加一个客户的信息
    public int Addonekh(kh tmp)
    {
        string sql = "insert into kh(Knum,Kpw,Kidcard,Kname,Kphone,Kaddress,Kwork) values('" + tmp.num + 
            "','" + tmp.pw +
            "','" + tmp.idcard + 
            "','" + tmp.name +
            "','" + tmp.phone +
            "','" + tmp.address + 
            "','" + tmp.work + "')";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //删除
    public int Deleteonekh(kh tmp)
    {
        string sql = "delete from kh where Knum='" + tmp.num + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //更新一个学生信息
    public int Updateoneuser(kh tmp)
    {
        string sql = "update kh set Kname='" + tmp.name +
                "', Kwork= '" + tmp.work +
                "', Kstate= '" + tmp.state +
                "', Kpw= '" + tmp.pw +
                "', Kidcard= '" + tmp.idcard +
                "', Kprovince= '" + tmp.province +
                "', Kcity= '" + tmp.city +
                "', Kbirth= '" + tmp.birth +
                "', Kqq= '" + tmp.qq +
                "' ,Kmail= '" + tmp.mail +
                "' ,Kphone= '" + tmp.phone +
                "', Kaddress= '" + tmp.address +
                "', Kproblem= '" + tmp.problem +
                "', Kanswer= '" + tmp.answer +
                "' where Knum= '" + tmp.num + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //删除学生信息
    
    public int Login(kh tmp)
    {
        string sql = "select count(*) from kh where Knum='" + tmp.num + "' and Kpw='" + tmp.pw + "'";
        int result = tmp.ExeScalar(sql);
        return result;
    }
    //读取一个学生的信息
    public SqlDataReader Getonekh(kh tmp)
    {
        string sql = "select * from kh where Knum='" + tmp.num + "'";
        SqlDataReader rd = tmp.ExeReader(sql);
        return rd;
    }
    //绑定省份
    public DataSet BindProvince()
    {
        kh tmp = new kh();
        string sql = "select * from T_province";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }

    //绑定市区
    public DataSet BindCity(string proid)
    {
        kh tmp = new kh();
        string sql = "select * from T_city where proID='" + proid + "'";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
    //获取所有学生的信息
    public DataSet GetAllKh()
    {
        kh tmp = new kh();
        string sql = "select * from kh";
        //,T_province,T_city where"
        //+
        //"t_users.u_PROVINCE=T_province.FID and T_province.FID=T_city.proID and "
        // +"t_users.u_city=T_city.FcityID";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
    public DataSet GetOneKh(kh tmp)
    {
        string sql = "select * from kh where Knum='" + tmp.num + "'";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
}